using System;
using System.Drawing;
using System.Windows.Forms;

class Program {
    static void Main(){
        // formEvent();
        // twoForm();
        twoEvent();
    }

    
    static void formEvent()
    {
        Form form = new Form();
        form.Text = "Paint事件";
        form.Paint += new PaintEventHandler(myPaintHandler);
        Application.Run(form);
    }

    static void myPaintHandler(object objSender,PaintEventArgs pea){
        Graphics g = pea.Graphics;
        g.Clear(Color.Chocolate);

        Form form = (Form)objSender;
        g.DrawString("Hello World",form.Font,Brushes.PapayaWhip,50,60);
    }

    static Form form1,form2;
    static void twoForm()
    {
        form1 = new Form();
        form2 = new Form();

        form1.Text = "Form1";
        form1.BackColor = Color.White;

        form2.Text = "Form2";
        form2.BackColor = Color.Red;

        form1.Paint += new PaintEventHandler(myPaintHandler2);
        form2.Paint += new PaintEventHandler(myPaintHandler2);

        form2.Show();
        Application.Run(form1);
    }

    static void myPaintHandler2(object objSender,PaintEventArgs pea){
        Form form = (Form)objSender;
        Graphics g = pea.Graphics;
        string str;

        if(form == form1){
            str = "From Form1";
        }else {
            str = "From form2";
        }

        g.DrawString(str,form.Font,Brushes.Black,0,0);
    }

    static void twoEvent()
    {
        var form = new Form();
        form.Text = "Two Event";
        form.BackColor = Color.White;
        form.Paint += new PaintEventHandler(myPaintHandler);
        form.Paint += new PaintEventHandler(myPaintHandler2);

        Application.Run(form);
    }

}